Imports System.Data.SqlClient

Friend Class DBFunctionText_Factory
    Inherits DBBase

    Public Sub ClearText( _
        ByVal lFunctionID As Long, _
        ByVal lFunctionRevID As Long)

        Dim sSQL As String = "delete from tDDFunctionText"
        sSQL = sSQL & " where"
        sSQL = sSQL & "   [FunctionID]=" & lFunctionID
        sSQL = sSQL & "   and [FunctionRevID]=" & lFunctionRevID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub AddText( _
        ByVal lFunctionID As Long, _
        ByVal lFunctionRevID As Long, _
        ByVal iOrder As Integer, _
        ByVal sText As String)

        Dim sSQL As String = "insert into tDDFunctionText ("
        sSQL = sSQL & " [FunctionID],"
        sSQL = sSQL & " [FunctionRevID],"
        sSQL = sSQL & " [Order],"
        sSQL = sSQL & " [Text]) values ("
        sSQL = sSQL & lFunctionID & ","
        sSQL = sSQL & lFunctionRevID & ","
        sSQL = sSQL & iOrder & ","
        sSQL = sSQL & ValueToDBValue(sText) & ")"

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Function GetText( _
        ByVal lFunctionID As Long, _
        ByVal lFunctionRevID As Long) As String

        Dim sText As String = ""

        Dim sSQL As String = "select"
        sSQL = sSQL & "     [Text]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     tDDFunctionText a"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [FunctionID]=" & ValueToDBValue(lFunctionID)
        sSQL = sSQL & "     and [FunctionRevID]=" & ValueToDBValue(lFunctionRevID)
        sSQL = sSQL & " order by"
        sSQL = sSQL & "     [Order]"

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        For Each oRow As DataRow In oData.Rows
            sText = sText & oRow.Item(0)
        Next

        oData.Dispose()

        Return sText
    End Function
End Class
